
class StickResume:
    def __init__(self, config):
        self.printer = config.get_printer()
        gcode = self.printer.lookup_object('gcode')
        gcode.register_command('STICK_RESUME_FILE', self.cmd_STICK_RESUME_FILE)

    def cmd_STICK_RESUME_FILE(self, gcmd):
        gcode = self.printer.lookup_object('gcode')
        sdcard = self.printer.lookup_object('virtual_sdcard')
        if sdcard.work_timer is not None:
            raise gcmd.error("SD busy")
        sdcard._reset_file()
        filename = gcmd.get("FILENAME")
        if filename[0] == '/':
            filename = filename[1:]
        sdcard._load_file(gcmd, filename, check_subdirs=True)
        file_pos = gcmd.get_int('POS', 0)
        sdcard.file_position = file_pos
        gcode.respond_info(f"action:stick resuming value: {filename} {file_pos}")
        sdcard.do_resume()


def load_config(config):
    return StickResume(config)
